﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta name="keywords" content="@Html.Raw(@ViewBag.keywords)">
    <meta name="description" content="@Html.Raw(@ViewBag.description)">
    <link rel="stylesheet" href="~/css/bootstrap.table.min.css" />
    <link rel="stylesheet" href="~/lib/adminlte/css/AdminLTE.icon.font.min.css" />

    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <!-- Bootstrap 3.3.7 -->
    <link href="~/css/bootstrap.min.css" rel="stylesheet" />

    <!-- Font Awesome -->
    <link href="~/css/font-awesome.min.css" rel="stylesheet" />

    <!-- Ionicons -->
    <link href="~/css/ionicons.min.css" rel="stylesheet" />

    <!-- Theme style -->
    <link href="~/lib/adminlte/css/AdminLTE.min.css" rel="stylesheet" />

    @*<title>
            @Html.Raw(@ViewBag.customer)@Html.Raw(@ViewBag.product)-@ViewBag.company
        </title>*@

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <!-- Google Font -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition login-page">

    <div id="app">
        <div class="login-box">

            <div class="login-logo">
                <a href="http://tuoshui.net.cn/" target="_blank"><b>@Html.Raw(@ViewBag.customer)</b>@Html.Raw(@ViewBag.product)</a>
            </div>

            <!-- /.login-logo -->
            <div class="login-box-body">
                <p class="login-box-msg">登录</p>
                <form onsubmit="return false" method="post">
                    <div class="form-group has-feedback">
                        <input type="text" v-model="UserNickname" id="test" autofocus class="form-control" placeholder="用户名">
                        <span class="fa fa-user form-control-feedback"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" v-model="Pwd" class="form-control" placeholder="密码" autocomplete="off">
                        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                    </div>

                    <div class="row">
                        <div class="col-xs-6">
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" v-model="isRemember"> 记住我
                                </label>
                            </div>
                        </div>
                        <div class="col-xs-2">
                        </div>
                        <div class="col-xs-4">
                            <button type="submit" :disabled="disabled" class="btn btn-primary btn-block btn-flat" v-bind:class="{ 'btn-grey': isSelected}" v-on:click="checkLogin">{{submit}}</button>
                        </div>
                        <!-- /.col -->
                    </div>
                    <div class="row">
                        <div class="col-xs-8"></div>
                        <div class="col-xs-4">
                            <button type="button" class="btn btn-danger btn-block btn-flat" v-bind:class="{ 'btn-grey': isSelected}" v-on:click="register">注册</button>
                        </div>
                    </div>
                </form>
            </div>
            <!-- /.login-box-body -->
        </div>
    </div>

    <div id="tree" style="margin-top:10px;"></div>

    <script src="~/lib/jquery/3.0/jquery.min.js"></script>
    @*<script src="~/js/snow.min.js"></script>*@
    <script src="~/lib/layer/layer.js"></script>
    <script src="~/js/vqypa.min.js"></script>
    <script src="~/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                UserNickname: '',
                Pwd: '',
                disabled: false,
                submit: "登录",
                reset: "取消",
                isSelected: false,
                isRemember: true
            },
            methods: {
                checkLogin: function () {
                    var _self = this;
                    _self.disabled = true;
                    _self.isSelected = true;
                    //es5写法
                    if (_self.UserNickname.length <= 0) {
                        layer.msg('用户名不能为空', { icon: 5 });
                        _self.disabled = false;
                        _self.isSelected = false;
                        return false;
                    }
                    if (_self.Pwd.length <= 0) {
                        layer.msg('密码不能为空', { icon: 5 });
                        _self.disabled = false;
                        _self.isSelected = false;
                        return false;
                    }
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });

                    if (this.isRemember) {
                        setCookie("uname", _self.UserNickname, 7);
                        setCookie("upass", _self.Pwd, 7);
                    }

                    yui.$axiospost('/Login/CheckLoginAsync', {
                        UserNickname: _self.UserNickname,
                        Pwd: _self.Pwd
                    })
                        .then(function (response) {
                            _self.disabled = false;
                            _self.isSelected = false;
                            if (response.data.Item1) {
                                _self.submit = "请等待...";
                                if (response.data.Item3.RoleId == 1) {
                                    location.href = "/StockIn/TjStockIn";
                                } else {
                                    location.href = "/StockIn/NewStockIn";
                                }
                            } else {
                                layer.close(index);
                                layer.msg(response.data.Item2 || errorMsg, { icon: 5 });
                            }
                        })
                        .catch(function (error) {
                            _self.disabled = false;
                            _self.isSelected = false;
                            layer.close(index);
                        });
                },
                cancel: function () {
                    var _self = this;
                    _self.Pwd = _self.UserNickname = "";
                },
                register: function () {
                    yui.layershow("添加用户", "/User/Register", 500, 650);
                },
                setCookie: function (cname, cvalue, exdays) {
                    var d = new Date();
                    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                    var expires = "expires=" + d.toGMTString();
                    document.cookie = cname + "=" + cvalue + "; " + expires;
                },
                getCookie: function (cname) {
                    var name = cname + "=";
                    var ca = document.cookie.split(';');
                    for (var i = 0; i < ca.length; i++) {
                        var c = ca[i].trim();
                        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
                    }
                    return "";
                }
            },
            mounted() {
                setTimeout(function () {
                    var uname = getCookie("uname");
                    var upass = getCookie("upass");
                    if (uname) {
                        this.UserNickname = uname;
                    }
                    if (upass) {
                        this.Pwd = upass;
                    }
                }, 500);
            }
        });

        function setCookie(cname, cvalue, exdays) {
            var d = new Date();
            d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
            var expires = "expires=" + d.toGMTString();
            document.cookie = cname + "=" + cvalue + "; " + expires;
        }

        function getCookie(cname) {
            var name = cname + "=";
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i].trim();
                if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
            }
            return "";
        }
    </script>
</body>
</html>